package com.woniu.microuserserver.mapper;

import com.woniu.microcommonsserver.entity.OrgInfoEntity;
import com.woniu.microcommonsserver.param.ResponseMsg;
import com.woniu.microuserserver.bean.DictBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface OrgMapper {

    //添加部门表与项目表的多对多关系
    @Insert("insert into org_pro_info values(null,#{o},#{p})")
    public int addOrgPro_id(@Param("o") int oid,@Param("p") int pid);

    //添加一个部门并返回ID
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into org_info values(null,#{o.orgName},#{o.takeEffectDate},#{o.loseEfficacyDate},#{o.orgType},#{o.orgLeader},'启用')")
    public int addOrg(@Param("o") OrgInfoEntity orgInfoEntity);

    @Select("select id,org_name orgName,take_effect_date takeEffectDate,lose_efficacy_date loseEfficacyDate,org_type orgType,org_leader orgLeader,status from org_info where org_info.id=#{id}")
    @ResultType(OrgInfoEntity.class)
    public OrgInfoEntity searchbyid(int id);

    @Select("select id,org_name orgName from org_info")
    public List<OrgInfoEntity> searchAllOrg();

    //添加字典
    @Insert("insert into dict values(null,#{d.dictName},#{d.dictDesc})")
    public int addDict(@Param("d") DictBean dictBean);

    //查询字典
    @Select("select id,dict_name as dictName,dict_desc as dictDesc from dict")
    public List<DictBean> sd();

    //删除字典
    @Delete("delete from dict where dict.id=#{id}")
    public int delDict(int id);
}
